package test.my.com.myapplicationtest.zhe_xian_tu_view.DynamicPathView.draw.DrawControl;

import android.annotation.TargetApi;
import android.graphics.Canvas;
import android.graphics.RectF;
import android.os.Build;

import test.my.com.myapplicationtest.zhe_xian_tu_view.DynamicPathView.draw.model.RoundRectTextModel;

/**
 * Created by ah on 2016/10/11.
 */

public class RoundRectTextControl extends DrawControl {

    private RoundRectTextModel roundRectTextModel;

    public RoundRectTextControl(Canvas canvas, RoundRectTextModel roundRectTextModel) {
        super(canvas);
        this.roundRectTextModel = roundRectTextModel;
    }

    @Override
    public void beginDraw() {
        paint.setColor(roundRectTextModel.getColor());
        float left = roundRectTextModel.getCenterX() - roundRectTextModel.getTextWidth()/2 - RoundRectTextModel.PADING_HORIZONTAL;
        float top = roundRectTextModel.getCenterY() - roundRectTextModel.getTextHeight()/2 - RoundRectTextModel.PADING_VERTICAL;
        float right = roundRectTextModel.getCenterX() + roundRectTextModel.getTextWidth()/2 + RoundRectTextModel.PADING_HORIZONTAL;
        float bottom = roundRectTextModel.getCenterY() + roundRectTextModel.getTextHeight()/2 + RoundRectTextModel.PADING_VERTICAL;
        RectF rect = new RectF(left, top, right, bottom);
        mCanvas.drawRoundRect(rect,roundRectTextModel.getRound(),roundRectTextModel.getRound(),paint);

        paint.setColor(roundRectTextModel.getTextColor());
        paint.setTextSize(roundRectTextModel.getTextSize());
//        paint.setTypeface(FontUtil.getInstance(mContext).getTypeface());
        float beginX = roundRectTextModel.getCenterX() - roundRectTextModel.getTextWidth()/2;
        float beginY = roundRectTextModel.getCenterY() + roundRectTextModel.getTextHeight()/4;
        mCanvas.drawText(roundRectTextModel.getTextContent(),beginX,beginY,paint);
    }
}
